package net.loyintean.pearlshell.wechat.messagepasser;

import org.dom4j.Document;
import org.dom4j.VisitorSupport;

import net.loyintean.pearlshell.wechat.common.MessageTypeEnum;
import net.loyintean.pearlshell.wechat.messagepasser.impl.BaseMessageBuilderImpl;
import net.loyintean.pearlshell.wechat.messagepasser.impl.EventMessageBuilder;
import net.loyintean.pearlshell.wechat.messagepasser.impl.TextMessageBuilderImpl;
import net.loyintean.pearlshell.wechat.model.BaseMessageModel;

public abstract class AbstractMessageBuilder extends VisitorSupport {

	public abstract BaseMessageModel getMessage(Document document);

	public static final AbstractMessageBuilder getBuilder(
			MessageTypeEnum messageType) {
		assert messageType != null;

		AbstractMessageBuilder builder;

		switch (messageType) {
		case text:
			builder = new TextMessageBuilderImpl();
			break;
		case event:
			builder = new EventMessageBuilder();
			break;

		default:
			builder = new BaseMessageBuilderImpl();
			break;
		}

		return builder;

	}
}
